package main

import (
	"fmt"
	_ "github.com/denisenkom/go-mssqldb"
	_ "github.com/go-sql-driver/mysql"
	"time"
)

//var wg sync.WaitGroup

var ChacheLen = 20
var isdebug = true

func startWrok() {

	var SqlserverConn = SqlConn{
		server:   "192.168.1.236",
		port:     1433,
		user:     "sa",
		password: "managerlan2017",
		database: "ayyh_hr",
	}

	var MysqlConn = SqlConn{
		server:   "192.168.1.56",
		port:     3306,
		user:     "root",
		password: "123456",
		database: "iheating_base",
	}

	//连接字符串
	sqlserverconnStr := fmt.Sprintf("server=%s;port%d;database=%s;user id=%s;password=%s", SqlserverConn.server, SqlserverConn.port, SqlserverConn.database, SqlserverConn.user, SqlserverConn.password)
	if isdebug {
		fmt.Println(sqlserverconnStr)
	}

	ch_gharea := make(chan string, ChacheLen)

	//wg.Add(1)
	go readGdArea(sqlserverconnStr, ch_gharea)

	mysqlconnStr := fmt.Sprintf("%s:%s@tcp(%s:%d)/%s?charset=utf8", MysqlConn.user, MysqlConn.password, MysqlConn.server, MysqlConn.port, MysqlConn.database)

	if isdebug {
		fmt.Println(mysqlconnStr)
	}

	//wg.Add(1)
	go writeGdArea(mysqlconnStr, ch_gharea)

}

//执行函数
func print5() {
	fmt.Println("每5s执行一次cron")
}

func main() {

	var ch chan int
	//定时任务
	ticker := time.NewTicker(time.Second * 60)
	go func() {
		for range ticker.C {
			startWrok()
			//fmt.Println(time.Now().Format("2006-01-02 15:04:05"))
		}
		ch <- 1
	}()
	<-ch

	//wg.Wait()

}
